package com.drug.service.impl;

import com.drug.domain.*;
import com.drug.mapper.*;
import com.drug.service.SettleaccountsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SettleaccountsServiceImpl implements SettleaccountsService {
    @Autowired
    private SupplierMapper supplierMapper;
    @Autowired
    private PurchaseOrderMapper purchaseOrderMapper;
    @Autowired
    private HospitalMapper hospitalMapper;
    @Autowired
    private DrugInformationMapper drugInformationMapper;
    @Autowired
    private PodiPdMapper podiPdMapper;
    @Autowired
    private PutInStorageMapper putInStorageMapper;
    @Autowired
    private StatementMapper statementMapper;

    /**
     * 查询结算单
     * @param map
     * @param page
     * @return
     */
    @Override
    public Result findjiesuandan(Map map, Integer page) {
        PageHelper.startPage(page,5);
        Result result = new Result<>();
        //药品类别
        DrugCategory drugCategory = new DrugCategory();
        //供货商
        Supplier supplier = new Supplier();
        //采购单
        PurchaseOrder purchaseOrder = new PurchaseOrder();
        //药品品目
        DrugAtegory drugAtegory = new DrugAtegory();
        //中间表
        PodiPd podiPd = new PodiPd();
        //根据医院名字查id
        Hospital hospital = new Hospital();
        // Integer hId = hospitalMapper.selectByName(hName);


        Statement statement = new Statement();
        //结算单编号
        String ponumber = (String) map.get("ponumber");
        if (ponumber==null || ponumber.equals("")){
            ponumber=null;
        }else {
            statement.setSNumber(ponumber);
        }
        //结算单名称
        String poname = (String) map.get("poname");
        if (poname==null || poname.equals("")){
            poname=null;
        }else {
            statement.setSName(poname);
        }
        //结算状态
        String postate = (String) map.get("postate");
        if (poname==null || poname.equals("")){
            poname=null;
        }else {
            statement.setSstate(postate);
        }
        //	医院
        String podihid = (String) map.get("podihid");
        if (podihid==null || podihid.equals("")){
            podihid=null;
        }else {
            Integer hId = hospitalMapper.selectByName(podihid);
            statement.setSUName(hId);
        }
        String ssupplier = (String) map.get("ssupplier");
        if (ssupplier==null || ssupplier.equals("") || ssupplier.equals("0")){
            ssupplier=null;
        }else {
            statement.setSSurid(Integer.parseInt(ssupplier));
        }
        List<Statement> statements = statementMapper.selectjs(statement);
        PageInfo<Statement> pageInfo = new PageInfo<>(statements);
        result.setData(pageInfo);
        return result;
    }

    @Override
    public Result findJieSuanDanAdd(CaiGouStatement caiGouStatement) {
        Result result = new Result();
        Integer pageNum = 1;
        pageNum = caiGouStatement.getPageNum();
        if (pageNum == null) {
            pageNum = 1;
        }
        PageHelper.startPage(pageNum, 5);
        List<PurchaseOrder> podiPds = statementMapper.JieSuanAdd(caiGouStatement);
        PageInfo pageInfo = new PageInfo(podiPds);
        result.setData(pageInfo);
        return result;
    }
}
